package ksv.cron;

import ksv.cron.v1.CronHandler;

import java.time.LocalDateTime;

/**
 * @创建人 xiaojiancheng
 * @时间 2020/8/15
 * @描述 $k$
 */
public class CronUtils {
    private static String ONLY = "%d %d %d %d * %d %d";
    private static String EVERY_DAY = "%d %d %d * * * *";
    //  在指定日期生效
    public static CronHandler only(LocalDateTime t, String eventName){
        String str = String.format(ONLY,t.getSecond(),t.getMinute(),t.getHour(),t.getDayOfMonth(),t.getMonthValue(),t.getYear());
        return new CronHandler(str,eventName);
    }

    //  每天执行
    public static CronHandler everyDay(LocalDateTime t, String eventName){
        String str = String.format(EVERY_DAY,t.getSecond(),t.getMinute(),t.getHour());
        return new CronHandler(str,eventName);
    }
}
